cc.Class({
    extends: cc.Component,

    properties: {

    },

    onEnable() {
        this.lobbyMain = cc.find("Canvas").getComponent("lobbyMain");
        this.lobbyNet = this.lobbyMain.lobbyNet;
        this.playerInfo = this.lobbyMain.playerInfo;

        this.facebookURL = null;
        this.whatsappURL = null;
    },

    start() {
        this.btnFacebook = this.node.getChildByName("btn").getChildByName("Facebook");
        this.btnWhatsapp = this.node.getChildByName("btn").getChildByName("WhatsAPP");
        this.btnFacebook.getComponent(cc.Button).interactable = false;
        this.btnWhatsapp.getComponent(cc.Button).interactable = false;
        this.getKefuUrl(); //获取客服链接
    },

    onClick(event, target) {
        this.lobbyMain.playClickSound();
        if (target == "close") {
            this.lobbyMain.hidePanel(this.node);
        } else if (target == "whatsapp") {
            this.lobbyMain.openUrl(this.whatsappURL);
        } else if (target == "facebook") {
            this.lobbyMain.openUrl(this.facebookURL);
        }
    },


    getKefuUrl() {
        let data = {
            action: "getKefuUrl",
            agentId: this.playerInfo.agentId,
        }
        this.lobbyNet.sendMessage(data);
    },

    onKefuUrl(data) {
        if (data.respCode == "SUCCESS") {
            let info = data.data;
            this.kefuData = info;
            this.setUrl(info);
        } else {
            this.showTips("Failed to get customer service information.");
        }
    },

    setUrl(info) {
        for (let i = 0; i < info.length; i++) {
            const ele = info[i];
            if (ele.name == "facebook") {
                this.facebookURL = ele.url;
                if (ele.isShow) {
                    this.btnFacebook.getComponent(cc.Button).interactable = true;
                } else {
                    this.btnFacebook.active = false;
                }
            } else if (ele.name == "whatsapp") {
                this.whatsappURL = ele.url;
                if (ele.isShow) {
                    this.btnWhatsapp.getComponent(cc.Button).interactable = true;
                } else {
                    this.btnWhatsapp.active = false;
                }
            }
        }
    },

    // update (dt) {},
});
